package com.wfs.demo;

import java.util.Scanner;

/**
 * 1 简单计算器：输入两个数字和一个运算符，进行加减乘除运算并显示结果
 */
public class Demo1 {
    public static void main(String[] args) {
        while ( true){
            System.out.printf("请输入第一个数字：");
            Scanner sc = new Scanner(System.in);
            Double num1 = sc.nextDouble();
            System.out.printf("请输入第二个数字：");
            Double num2 = sc.nextDouble();
            System.out.printf("请输入运算符(+ - * /)：");
            String operator = sc.next();
            calculator(num1, num2, operator);
            System.out.println("是否继续？y/n");
            String flag = sc.next();
            if ("n".equals(flag)) {
                break;
            }
            System.out.println("-----------------");
        }
    }
    public static void calculator(double num1, double num2, String operator) {
        switch (operator){
            case "+": System.out.println(num1 + num2);break;
            case "-": System.out.println(num1 - num2);break;
            case "*": System.out.println(num1 * num2);break;
            case "/": System.out.println(num1 / num2);break;
            default: System.out.println("输入错误");
        }
    }
}
